<!DOCTYPE HTML>
<html>
<head>
    <script type="text/javascript" src="../js/common.js"></script>
    <title>添加权限</title>
</head>
<body>
<div class="pd-20">
    <div class="Huiform">
        <form class="form" onsubmit="return false">
            <table class="table table-bg">
                <tbody>
                <input type="hidden" style="width:200px" class="input-text" id="id"
                       name="id" readonly>

                <input type="hidden" style="width:200px" class="input-text" id="p_id"
                       name="p_id" readonly>
                <tr>
                    <th width="100" class="text-r"><span class="c-red">*</span> 上级菜单：</th>
                    <td><input type="text" style="width:200px" class="input-text" id="p_permission_name" readonly></td>
                </tr>

                <tr>
                    <th width="100" class="text-r"><span class="c-red">*</span> 权限名称：</th>
                    <td><input type="text" style="width:200px" class="input-text" value="" placeholder=""
                               id="permission_name"
                               name="permission_name" datatype="*2-16" nullmsg="权限名称不能为空"></td>
                </tr>

                <tr>
                    <th width="100" class="text-r"><span class="c-red"></span><a
                            href="https://getbootstrap.com/docs/3.3/components/" target="view_window">icon_url：</a></th>
                    <td><input type="text" style="width:200px" class="input-text" value="" placeholder="" id="icon_url"
                               name="icon_url"></td>
                </tr>

                <tr>
                    <th class="text-r"><span class="c-red">*</span> 权限类型：</th>
                    <td><label>
                        <input name="permission_type" type="radio" id="permission_type_0" value="1" checked>
                        菜单</label>
                        <label>
                            <input type="radio" name="permission_type" value="2" id="permission_type_1">
                            按钮</label></td>
                </tr>

                <tr>
                    <th width="100" class="text-r"><span class="c-red"></span> url：</th>
                    <td><input type="text" style="width:200px" class="input-text" value="" placeholder=""
                               id="url" name="url"></td>
                </tr>

                <tr>
                    <th width="100" class="text-r">js方法：</th>
                    <td><input type="text" style="width:200px" class="input-text" value="" placeholder=""
                               id="method"
                               name="method"></td>
                </tr>

                <tr>
                    <th class="text-r">顺序：</th>
                    <td><input type="number" style="width:300px" class="input-text" value="" placeholder=""
                               id="permission_order" name="permission_order"></td>
                </tr>
                <tr>
                    <th></th>
                    <td>
                        <button type="submit" class="btn btn-primary"><i
                                class="glyphicon glyphicon-ok"></i>确定
                        </button>
                    </td>
                </tr>
                </tbody>
            </table>
        </form>
    </div>
</div>
<script type="text/javascript">
    $(".form").Validform({
        callback: function () {
            var data = $(".form").serialize();
            requestService("/permission/save", "post", true, data,
                function (result) {
                    layer.msg(result.desc);
                    setTimeout(function () {
                        parent.window.location.reload();
                        layer_close();
                    }, 500);
                }, null);
        }
    });
    var flag = getQueryVariable("flag");
    if (flag == 0) { //编辑
        var id = getQueryVariable("id");
        var p_id = getQueryVariable("p_id");
        var p_text = getQueryVariable("p_text");
        $("#id").val(id);
        $("#p_id").val(p_id);
        $("#p_permission_name").val(p_text);
        requestService("/permission/get/" + id, "get", true, null,
            function (result) {
                $("#permission_name").val(result.data.permission_name);
                $("#icon_url").val(result.data.icon_url);
                if (result.data.permission_type == 1) {
                    $("#permission_type_0").click();
                } else {
                    $("#permission_type_1").click();
                }
                $("#url").val(result.data.url);
                $("#method").val(result.data.method);
                $("#permission_order").val(result.data.permission_order);
            }, null);
    } else {
        //添加
        var p_id = getQueryVariable("p_id");
        var p_text = getQueryVariable("p_text");
        $("#p_id").val(p_id);
        $("#p_permission_name").val(p_text);
    }
</script>
</body>
</html>